#! /bin/bash

set -e

pr_info () {
    echo -e "\033[0;32m$*\033[0m"
}

cd_bbb () {
    if [ -z $BBB_WS ]; then
        echo "No env: BBB_WS"
        exit
    fi
    cd $BBB_WS
}


cd_bbb

cd linux/

rm -rf output/

pr_info "[build] linux defconfig"
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=output -j `nproc` omap2plus_defconfig

pr_info "[build] linux zImage"
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=output -j `nproc` zImage

pr_info "[build] linux dtb"
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=output -j `nproc` ti/omap/am335x-boneblack.dtb

pr_info "[build] linux modules"
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=output -j `nproc` modules
